package observer;

import java.util.ArrayList;
import java.util.List;

/**
 * 具体被观察者目标
 **/
public class UpdateWatchedSubject implements IWathedSubject {

	private List<IWatcher> list;

	public UpdateWatchedSubject() {

		this.list = new ArrayList<>();
	}

	@Override
	public void add(IWatcher watcher) {

		this.list.add(watcher);
	}

	@Override
	public void remove(IWatcher watcher) {

		this.list.add(watcher);
	}

	@Override
	public void notifyWatchers() {

		for (IWatcher watcher : list) {
			watcher.update();
		}
	}

	@Override
	public void update() {

		System.out.println("目标更新中....");
		notifyWatchers();
	}

}
